package com.lanchewuyou.user.driver.yancheui;

import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageButton;

import com.lanchewuyou.user.driver.R;
import com.lanchewuyou.user.driver.modul.Config;
import com.lanchewuyou.user.driver.modul.PagerSlidingTabStrip;

import java.util.ArrayList;
import java.util.List;

/**
 * 验车订单主界面,展示已完成和未完成列表
 */
public class YancheMainActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private List<Fragment> fragmentList;
    private PagerSlidingTabStrip mPagerSlidingTabStrip;
    private FragmentPagerAdapter fragmentPagerAdapter;
    private ImageButton yancheMainBack;
    public static String DRIVERID;

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yanche_main);
        SharedPreferences sharedPreferences = getSharedPreferences(Config.PASSWORD_PATH, Activity.MODE_PRIVATE);
        DRIVERID = sharedPreferences.getString("driverid", "");
        initViews();
        initTabsValue();
    }

    private void initViews() {
        yancheMainBack = (ImageButton) findViewById(R.id.yanche_main_back);
        yancheMainBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //准备fragment
        fragmentList = new ArrayList<Fragment>();
        android.support.v4.app.Fragment fragment1 = new YancheMainFragment1();
        android.support.v4.app.Fragment fragment2 = new YancheMainFragment2();
        fragmentList.add(fragment1);
        fragmentList.add(fragment2);
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentPagerAdapter = new FragmentPagerAdapter(fragmentManager) {
            private String[] Titles = {"未完成订单", "已完成订单"};

            @Override
            public Fragment getItem(int i) {
                return fragmentList.get(i);
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return Titles[position];
            }

            @Override
            public int getCount() {
                return 2;
            }
        };
        viewPager = (ViewPager) findViewById(R.id.yanche_viewpager);
        viewPager.setAdapter(fragmentPagerAdapter);
        mPagerSlidingTabStrip = (PagerSlidingTabStrip) findViewById(R.id.yanche_pagersliding);
        mPagerSlidingTabStrip.setViewPager(viewPager);
        mPagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
            }

            @Override
            public void onPageSelected(int i) {
            }

            @Override
            public void onPageScrollStateChanged(int i) {
            }
        });
    }

    //TAB设置
    private void initTabsValue() {
        // 底部游标颜色
        mPagerSlidingTabStrip.setIndicatorColor(Color.parseColor("#ffffff"));
        mPagerSlidingTabStrip.setUnderlineHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                0, getResources().getDisplayMetrics()));
        // 游标高度
        mPagerSlidingTabStrip.setIndicatorHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                1, getResources().getDisplayMetrics()));
        // 选中的文字颜色
        mPagerSlidingTabStrip.setSelectedTextColor(Color.parseColor("#ffffff"));
        mPagerSlidingTabStrip.setShouldExpand(true);
        // 正常文字颜色
        mPagerSlidingTabStrip.setTextColor(Color.parseColor("#5983be"));
        mPagerSlidingTabStrip.setTextSize(40);
    }

}
